// 导入 Eachars 组件
import echarts from 'echarts'
import _ from 'lodash'

export default {
  data() {
    return {
      // 查询参数
      queryinfo: {
        pageNo: 1,
        pageSize: 10,
        status:2,
        mobile: null,
        date: null
      },
      total: 0,
      shenGouList: [],
      isShowImage: false,
      dateValue: '',
      showDate: false,
      dateValue: '',
      shaixuanContent:'已完成',
      statusList: [
        {
          name: '待支付',
          status: 0
        },
        {
          name: '进行中',
          status: 1
        },
        {
          name: '已完成',
          status: 2
        },
        {
          name: '审核失败',
          status: 3
        },
        {
          name: '已失效',
          status: 4
        }
      ],
      status: 2,
      telephone: ''
    }
  },
  async mounted() {
    // 根据查询参数获取商品列表

    this.getShenGouList();
    // const { data: res } = await this.$http.get('goods', { params: this.queryinfo })

    // if (res.meta.status !== 200) return this.$message.error('获取商品列表失败！')
    // this.goodslist = res.data.goods
    // this.total = res.data.total
    // console.log(res)

  },
  methods: {
    qingkong(){
      this.queryinfo.date=null;
      this.queryinfo.mobile=null;
      this.queryinfo.status=null;
      this.telephone="";
      this.status="";
      this.dateValue="";
      this.queryinfo.pageNo = 1;
      this.shaixuanContent="按状态筛选";
      this.getShenGouList();
    },
    shaixuan() {
      // console.log(this.status,this.status);
      // this.status=this.status.toString();
      //this.queryinfo.status = this.status;
      this.queryinfo.status = this.status;
      // if (this.status) {

      //   console.log(4444);
      //   this.queryinfo.status = this.status;
      // }
      if (this.dateValue) {
        //let data = new Date(this.queryinfo.date);
        var date = new Date(this.dateValue);
        var y = date.getFullYear();
        var m = date.getMonth() + 1;
        m = m < 10 ? ('0' + m) : m;
        var d = date.getDate();
        d = d < 10 ? ('0' + d) : d;
        this.queryinfo.date = y+'-'+m+'-'+d + ' 00:00:00';
      }

      if (this.telephone) {
        var strTemp = /^1[3|4|5|6|7|8|9][0-9]{9}$/;
        if (!strTemp.test(Number(this.telephone))) {
          this.$message.error('手机号格式不正确')
          return;
        } else {
          this.queryinfo.mobile = this.telephone;
        }
      }
      this.queryinfo.pageNo = 1;
      this.getShenGouList();
    },
    handleCommand(type) {
      console.log(type);
      this.shaixuanContent=this.statusList[type].name;
      this.status=type;
    },
    isShowDate() {
      console.log(5454);
      this.showDate = !this.showDate;
    },
    async tongyi(data) {
      console.log(data);
      const { data: res } = await this.$http.post('/manage/successSubscriptionOrder', { queryId: data.row.id });
      console.log(res);
      if (res.status == 1) {
        this.shenGouList[data.$index].status = 2;
        this.$message.success('订单已同意');
      } else {

        this.$message.error(res.message)
      }
    },
    async jujue(data) {
      console.log(data);
      const { data: res } = await this.$http.post('/manage/refuseSubscriptionOrder', { queryId: data.row.id });
      console.log(res);
      if (res.status == 1) {
        this.shenGouList[data.$index].status = 3;
        this.$message.success('订单已拒绝');
      } else {
        this.$message.error(res.message)
      }
    },
    showImageMask() {
      console.log(45454);
      this.isShowImage = true;
    },
    cancelMask() {
      this.isShowImage = false;
    },
    async getShenGouList() {
      // let params = {
      //   "pageNo": this.queryinfo.pagenum,
      //   "pageSize": this.queryinfo.pagesize
      // }
      const { data: res } = await this.$http.post('/manage/getAllSubscriptionOrder', this.queryinfo)//, { params: this.queryinfo }

      console.log(res);
      res.data.list.forEach(element => {
        if (element.certificate.length > 0) {
          element.image = "点击查看"
        } else {
          element.image = "暂无图片"
        }

      });
      this.shenGouList = res.data.list;
      this.total = res.data.total
    },
    // 监听 pageSize 的变化，并立即获取最新的数据
    handleSizeChange(newSize) {
      this.queryinfo.pageSize = newSize
      this.getShenGouList()
    },
    // 监听 pageNum 的变化，并立即获取最新的数据
    handleCurrentChange(newPage) {
      this.queryinfo.pageNo = newPage
      this.getShenGouList()
    },
  }
}
